﻿using System;
using MyWeb.Business;
using MyWeb.Common;

namespace MyWeb.Controls
{
    public partial class u_new_default : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                NewsTop1();
                NewsTop3();
                NewsTop6R();
            }
        }
        private void NewsTop1()
        {
            var list = NewsService.News_GetByTop("1", "Active = '1' and [Index] = '1'", "[Date] desc");
            if(list.Count > 0)
            {
                var s = "<div class=\"newTop1\"><div class=\"box\">\n";
                foreach (var t in list)
                {
                    var links = "/tin-tuc/" + t.Tag + "/" + t.Id + ".html";
                    s += "<a href=\""+ links +"\" title='"+ t.Name +"'><img src='"+ StringClass.ThumbImage(t.Image) +"' alt='"+ t.Name +"' /></a>";
                    s += "<h2 class=\"TitleNew\"><a href=\""+ links +"\" title='"+ t.Name +"' class=\"link\">"+ t.Name +"</a></h2>";
                    s += "<p>"+ StringClass.SubText(t.Content, 50) +"</p>";
                }
                s += "</div></div>\n";
                ltrNewsTop1.Text = s;
            }
        }
        private void NewsTop3()
        {
            var list = NewsService.News_GetByTop("4", "Active = '1' and [Index] = '1'", "[Date] desc");
            if(list.Count > 0)
            {
                var s = "<div class=\"newTop3 clear\"><div class=\"boxContent\">\n";
                for (var i = 0; i < list.Count; i++)
                {
                    var links = "/tin-tuc/" + list[i].Tag + "/" + list[i].Id + ".html";
                    if(i > 0)
                    {
                        s += "<div class=\"Top3Detail\"><div class=\"BoxTop3\">";
                        s += "<a href=\"" + links + "\" title='" + list[i].Name + "'><img src='" + StringClass.ThumbImage(list[i].Image) + "' alt='" + list[i].Name + "' /></a>";
                        s += "<h2><a href=\"" + links + "\" title='" + list[i].Name + "' class=\"link\">" + list[i].Name + "</a></h2>";
                        s += "</div></div>";
                    }
                }
                s += "</div></div>\n";
                ltrNewsTop3.Text = s;
            }
        }
        private void NewsTop6R()
        {
            var list = NewsService.News_GetByTop("10", "Active = '1' and [Index] = '1'", "[Date] desc");
            if(list.Count > 0)
            {
                var s = "<div class=\"newRight\"><div class=\"box\"><ul>\n";
                for (var i = 0; i < list.Count; i++)
                {
                    var links = "/tin-tuc/" + list[i].Tag + "/" + list[i].Id + ".html";
                    if(i > 3)
                    {
                        s += "<li><a href=\"" + links + "\" title='" + list[i].Name + "'>" + list[i].Name + "</a></li>";
                    }
                }
                s += "</ul></div></div>\n";
                ltrNewsTop6R.Text = s;
            }
        }
    }
}